<%
   file_complexity=measure('file_complexity')
   function_complexity=measure('function_complexity')
   class_complexity=measure('class_complexity')

   if file_complexity || function_complexity || class_complexity
     complexity=measure('complexity')
%>

  <div class="widget-row">
    <div class="widget-span widget-span-5">
      <div class="widget-measure-container">
        <div class="widget-measure widget-measure-main">
          <span class="widget-label"><%= message('widget.complexity.name') -%></span>
          <% if function_complexity %>
            <span class="nowrap">
              <%= format_measure(function_complexity, :url => url_for_drilldown(function_complexity)) %>
              <%= dashboard_configuration.selected_period? ? format_variation(function_complexity) : trend_icon(function_complexity) -%>
              <span class="small"><%= message('widget.complexity.per_method.suffix') %></span>
            </span>
          <% end %>
          <% if class_complexity %>
            <br>
            <span class="nowrap">
              <%= format_measure(class_complexity, :url => url_for_drilldown(class_complexity)) %>
              <%= dashboard_configuration.selected_period? ? format_variation(class_complexity) : trend_icon(class_complexity) -%>
              <span class="small"><%= message('widget.complexity.per_class.suffix') %></span>
            </span>
          <% end %>
          <% if file_complexity %>
            <br>
            <span class="nowrap">
              <%= format_measure(file_complexity, :url => url_for_drilldown(file_complexity)) %>
              <%= dashboard_configuration.selected_period? ? format_variation(file_complexity) : trend_icon(file_complexity) -%>
              <span class="small"><%= message('widget.complexity.per_file.suffix') %></span>
            </span>
          <% end %>
          <% if complexity %>
            <br>
            <span class="nowrap">
              <%= message('widget.complexity.total') -%>
              : <%= format_measure(complexity, :url => url_for_drilldown(complexity)) %>
              <%= dashboard_configuration.selected_period? ? format_variation(complexity) : trend_icon(complexity) -%>
            </span>
          <% end %>
        </div>
      </div>
    </div>

    <div class="widget-span widget-span-7">
      <%
         function_distribution=measure('function_complexity_distribution')
         class_distribution=measure('class_complexity_distribution')
         file_distribution=measure('file_complexity_distribution')
         distributions=[function_distribution, class_distribution, file_distribution].compact
         selected_distribution=nil
         if distributions.size>0
           selected_distribution=distributions.first
         end
         if selected_distribution
      %>
        <div class="dashbox" id="cmp_charts">
          <script type='text/javascript'>
            //<![CDATA[
            function selectComplexity(metric) {
              $j('#cmp_charts .chart').hide();
              $j('#chart_' + metric).show();
            }
          </script>
          <style>
            #cmp_charts form {
              font-size: 93%; padding-left: 30px;
            }

            #cmp_charts form label {
              padding-right: 5px;
            }
          </style>
          <% distributions.each do |distribution_measure| %>
            <%= render :partial => 'project/widgets/complexity_chart', :locals => {:metric => distribution_measure.metric.key, :title => distribution_measure.metric.description, :visible => (selected_distribution==distribution_measure)} %>
          <% end %>

          <form>
            <%
               count_dist=0
               if function_distribution
                 count_dist+=1
            %>
              <input type="radio" name="cmp_dist" value="function_complexity_distribution" id="cmp_dist_function_complexity_distribution" onClick="selectComplexity('function_complexity_distribution');" <%= 'checked' if function_distribution==selected_distribution -%>/>
              <label for="cmp_dist_function_complexity_distribution"><%= message('metric.functions.name') -%></label>
            <%
               end
               if class_distribution
                 count_dist+=1
            %>
              <input type="radio" name="cmp_dist" value="class_complexity_distribution" id="cmp_dist_class_complexity_distribution" onClick="selectComplexity('class_complexity_distribution');" <%= 'checked' if class_distribution==selected_distribution -%>/>
              <label for="cmp_dist_class_complexity_distribution"><%= message('metric.classes.name') -%></label><%= '<br/>' if count_dist==2 %>
            <%
               end
               if file_distribution
                 count_dist+=1
            %>
              <input type="radio" name="cmp_dist" value="file_complexity_distribution" id="cmp_dist_file_complexity_distribution" onClick="selectComplexity('file_complexity_distribution');" <%= 'checked' if file_distribution==selected_distribution -%>/>
              <label for="cmp_dist_file_complexity_distribution"><%= message('metric.files.name') -%></label>
            <% end %>

          </form>

        </div>
      <% end %>
    </div>
  </div>
<% end %>
